<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2017/1/7
  Time: 11:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>对比记录</title>
      <link rel="stylesheet" type="text/css" href="<%=basePath%>css/easyui.css" />
      <link rel="stylesheet" type="text/css" href="<%=basePath%>css/icon.css" />
      <script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
      <script type="text/javascript" src="<%=basePath%>js/jquery.easyui.min.js"></script>
      <script type="text/javascript" src="<%=basePath%>js/easyui-lang-zh_CN.js"></script>
      <script type="text/javascript" src="<%=basePath%>js/json2.js"></script>
    </head>
    <body>
    <div id="main" class="easyui-layout" fit="true">
        <%--建个表显示记录--%>
        <table id="dataGrid" toolbar="#div_toolbar" fitColumns="true"
               fit="true"  style="width:auto;height:100%"
               data-options="pageSize:20">
        </table>
    </div>
    <div id="div_toolbar" style="">
         <span style="">
            <label style="color:#313031">任务名：</label>
            <select class="easyui-combobox" id="task_name"  name="task_name"  style="width:300px"
                    editable="false" >
                    </select>
          </span>
        </div>
    </div>

  <script type="text/javascript">

      //从表中第offset条数据开始查询
      var page = 1;
      //查询limit条数据 默认100条
      var size =25;
      var actionType="",dataGrid;

  $(function() {

        initiDataGrid();//初始化表格DataGrid
        initiCombobox();//初始化下拉框
  });

      /**
       * 备份库名 选择事件
       */
      $('#task_name').combobox({
          editable:false,//是否可输入
          onSelect:function(record){
              var id=record.value;//获取备份数据库名
              actionType=record.text;
              var param=({page:page,size:size,actionType:actionType});
              loadPage(param);
          }
      });
      /**
       * 初始化下拉框
       */
      function initiCombobox(){
          $.ajax({

              url: '<%=basePath%>backupRecord/loadActionType',
              type: 'post',
              success:function(res){
                  $('#task_name').combobox('loadData',res.data);
              }
          });
      }

    /**
     * 初始化表格DataGrid
     */
    function initiDataGrid(){
        //表格式
        dataGrid=$('#dataGrid').datagrid({
            singleSelect: true,
            pagination : true,
            rownumbers:true,
            nowrap:false,
            fitColumns :false,
            columns: [[
                {field: 'id', title: 'id',width: '5%', hidden: false},
                {field: 'action_type',width: '20%', title: '任务名'},
                {field: 'src_database', width: '6%', title: '源数据库'},
                {field: 'src_table', width: '6%', title: '源表'},
                {field: 'tgt_database', width: '6%', title: '目标数据库'},
                {field: 'tgt_table', width: '6%', title: '目标表'},
                {field: 'from_number', width: '6%', title: '起始行号'},
                {field: 'to_number', width: '6%', title: '终止行号'},
                {field: '处理数据量', width: '5%', title: '处理数据量',
                    formatter:function(value,row,index){
                        return row.to_number - row.from_number;
                    }
                },
                {field: 'state', width: '4%', title: '状态',
                    formatter:function(value,row,index){
                        if(value==0){
                            return "成功";
                        }else{
                            return "失败";
                        }
                    }
                },
                {field: 'create_time', width: '8%', title: '创建时间'},
                {field: 'message', width: '22%', title: '提示信息'}
            ]]
        });


        loadPage({page:page,size:size,actionType:""});//要补充要补充要补充


    }
      //加载数据库中全部数据
      function loadPage(param) {
          $.ajax({
              url: "<%=basePath%>backupRecord/loadPage",//要改要改要改
              type: 'post',
              timeout: 20000,
              data: param,
              success: function (res) {
                  if (res.code == 200) {
                      dataGrid.datagrid("loadData", res.data.data);
                      dataGrid.datagrid('getPager').pagination({//分页对象
                          pageSize:res.data.size,
                          total: res.data.total,
                          pageNumber: res.data.page,
                          pageList: [25, 50, 75, 100],
                          onSelectPage: function (pageNumber, pageSize) {
                              actionType=res.data.actionType;
                              var param = {page: pageNumber, size: pageSize, actionType:actionType }
                              loadPage(param);
                          }
                      });
                  } else {
                      $.messager.show({
                          title: '提示',
                          width: 250,
                          height: 140,
                          msg: "没有任何数据！"
                      });
                  }
              },
              error: function (error) {
                  $.messager.show({
                      title: '提示',
                      width: 250,
                      height: 140,
                      msg: "<div class='messager-icon messager-error'></div><div>系统繁忙，请稍后再试！</div>"
                  });
              }
          });
      }

  </script>
  </body>
</html>

